package com.lingx.web.api.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.lingx.model.impl.DefaultEntity;
import com.lingx.service.ModelService;
import com.lingx.service.UserService;
import com.lingx.utils.TokenUtils;
import com.lingx.utils.Utils;
import com.lingx.web.api.IApi;
@Component
public class Api8001 extends AbstractAuthApi implements IApi{
	@Resource
	private JdbcTemplate jdbcTemplate;
	@Resource
	private ModelService modelService;

	@Resource
	private UserService userService;
	@Override
	public int getApiCode() {
		return 8001;
	}
	@Override
	public String getApiName() {
		return "获取属性与操作列表";
	}
	
	@Override
	public Map<String, Object> api(Map<String, Object> params) {
		Map<String,Object> ret=IApi.getRetMap(1, "操作成功");
		String e=IApi.getParamString(params, "e", "");
		String m=IApi.getParamString(params, "m", "");
		String eid=IApi.getParamString(params, "eid", "");
		String token=IApi.getParamString(params, "lingxtoken", "");
		String userid=TokenUtils.getTokenDataUserId(token);
		if(Utils.isNull(e)) {
			ret.put("code", -1);
			ret.put("message","参数e不可为空");
			return ret;
		}
		if(Utils.isNull(m))m="grid";
		if(this.userService.isAuthFunc(userid, e,m)) {
			DefaultEntity dm=this.modelService.getEntity(e);
			if("grid".equals(m)) {
				ret.put("data", this.modelService.getGridParams(dm,params));
			}else {
				ret.put("data", this.modelService.getEditParams(dm,m,eid,params));
			}
		}else {
			ret.put("code", 40002);
			ret.put("message","权限不足，"+e+"-"+m);
			return ret;
		}
		
		
		return ret;
	}
	public boolean isLog() {
		return false;
	}
}
